<?php
/**
 * MageWorx
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the MageWorx EULA that is bundled with
 * this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.mageworx.com/LICENSE-1.0.html
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@mageworx.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade the extension
 * to newer versions in the future. If you wish to customize the extension
 * for your needs please refer to http://www.mageworx.com/ for more information
 * or send an email to sales@mageworx.com
 *
 * @category   MageWorx
 * @package    MageWorx_Adminhtml
 * @copyright  Copyright (c) 2009 MageWorx (http://www.mageworx.com/)
 * @license    http://www.mageworx.com/LICENSE-1.0.html
 */

/**
 * MageWorx Adminhtml extension
 *
 * @category   MageWorx
 * @package    MageWorx_Adminhtml
 * @author     MageWorx Dev Team <dev@mageworx.com>
 */

class MageWorx_Adminhtml_Block_Deliveryzone_Shippingmethods_Edit_Tab_Shippingmethod extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('carrier_'.$this->getId(), array('legend' => Mage::helper('deliveryzone')->__('%s Settings', $this->getLabel())));

        $fieldset->addField($this->getCarrier()->getId().'_active', 'select', array(
            'label'     => Mage::helper('deliveryzone')->__('Allowed'),
            'title'     => Mage::helper('deliveryzone')->__('Shipping Method Allowed'),
            'name'      => 'active['.$this->getCarrier()->getId().']',
            'required'  => true,
            'options'   => array(
                '1' => Mage::helper('deliveryzone')->__('Yes'),
                '0' => Mage::helper('deliveryzone')->__('No'),
            ),
        ));

        $allowedMethods = $this->getCarrier()->getAllowedMethods();
        if (count($allowedMethods) > 1) {
            $methods = array();
            foreach ($allowedMethods as $value => $label) $methods[] = array('label' => $label, 'value' => $value);
            $fieldset->addField($this->getCarrier()->getId().'_methods', 'multiselect', array(
                'label'  => Mage::helper('deliveryzone')->__('Allowed Methods'),
                'name'   => 'methods['.$this->getCarrier()->getId().'][]',
                'values' => $methods,
            ));
        } else {
            $fieldset->addField($this->getCarrier()->getId().'_methods', 'hidden', array(
                'name'   => 'methods['.$this->getCarrier()->getId().'][]',
//				'values' => $methods,
            ));
            $methods = array_keys($allowedMethods);
            Mage::registry('zone_data')->setData($this->getCarrier()->getId().'_methods', $methods[0]);
        }

        if (Mage::getSingleton('adminhtml/session')->getZoneData()) {
            $form->setValues(Mage::getSingleton('adminhtml/session')->getZoneData());
            Mage::getSingleton('adminhtml/session')->setZoneData(null);
        } elseif (Mage::registry('zone_data')) {
            $form->setValues(Mage::registry('zone_data')->getData());
        }
        return parent::_prepareForm();
    }
}